package com.nbicc.dp.web.panel.controller;

import com.nbicc.core.common.RequestPageObj;
import com.nbicc.db.modular.dp.panel.model.Panel;
import com.nbicc.service.modular.dp.panel.service.PanelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

/**
 * @Author: lilingyan
 */
@Api(value = "dp:面板" , description = "")
@RestController
@RequestMapping("/panel")
public class PanelController {

    @Autowired
    private PanelService panelService;

    @ApiOperation(value = "按序列号查询面板")
    @GetMapping("/{serialNum:.+}")
    public ResponseEntity<ModelMap> selectBySerialNum(@PathVariable String serialNum){
        return panelService.selectBySerialNum(serialNum);
    }

    @ApiOperation(value = "分页查询")
    @PostMapping("/find")
    public ResponseEntity<ModelMap> find(@RequestBody RequestPageObj<Map<String,Object>> requestPageObj){
        return panelService.find(requestPageObj);
    }

    @ApiOperation(value = "添加" , notes = "序列号必填并唯一")
    @PostMapping
    public ResponseEntity<ModelMap> insert(@RequestBody Panel panel){
        return panelService.insert(panel);
    }

    @ApiOperation(value = "修改", notes = "以序列号修改(必传序列号)")
    @PutMapping
    public ResponseEntity<ModelMap> updateBySerialNum(@RequestBody Panel panel){
        return panelService.updateBySerialNum(panel);
    }

    @ApiOperation(value = "删除", notes = "以序列号")
    @DeleteMapping("/{serialNum:.+}")
    public ResponseEntity<ModelMap> deleteBySerialNum(@PathVariable String serialNum){
        return panelService.deleteBySerialNum(serialNum);
    }

}
